
	<body>
		<div class="layout">
			<!--header-->
			<div class="wrapper">
				<div class="header">
					<a class="s_preson" href="{:U('Users/index')}" target="_blank"><i class="s_icon s_author"></i></a>
                    <form action="{:U('Index/index')}" method='POST'>
                        <div class="store">
                            <select class="select" name="sellerID" onchange="subSellerName()">
                                <if condition="($sellerName eq '')">
                                    <option value="">-- 请选择 --</option>
                                <else />
                                    <option value="{$sellerID}"><span style="float:left; width:100%; text-align:right;">{$sellerName}</span></option>
                                </if>
                                <volist name="businessFull" id="co">
                                    <option value="{$co.id}"><span style="float:left; text-align:right;">{$co.nick}</span></option>
                                </volist>
                            </select>
                            <input type="submit" value="ok" id="subSN" style="display:none;"/>
                            <label>﹀</label>
                        </div>
                    </form>
					<div class="s_search">
                        <a href="{:U('Search/index')}">
						    <i class="s_icon s_searchBtn"></i>
                        </a>
					</div>
				</div>
			</div>
			<script>
                function subSellerName()
                {
                    $("#subSN").trigger("click");
                }
            </script>
			<!--幻灯片-->
			<div class="swiper-container">
		        <div class="swiper-wrapper">
		            <div class="swiper-slide"><a href="#" target="_blank"><img src="__PUBLIC__img/banner1.jpg" alt="" title=""/></a></div>
		            <div class="swiper-slide"><a href="#" target="_blank"><img src="__PUBLIC__img/banner2.jpg" alt="" title=""/></a></div>
		        </div>
		        <div class="swiper-pagination"></div>
		    </div>
			
			<div class="storeMain clearfix">
				<ul class="storeNav">
					<!--<li class="cur">大米 <span class="tips">新</span><i class="num">1</i></li>-->
                    <volist name="cate" id="ro">
					    <!--<li>{$ro.name}<span class="tips">新</span><i class="num">1</i></li>-->
                        <li>
                            {$ro.name}
                                <i class="num">{$ro.sumCartNum}</i>
                        </li>
                    </volist>
                    <li>
                        店长推荐
                        <i class="num"></i>
                    </li>
				</ul>
				<!--第一个循环-->
                <volist name="product" id="vo">
				<div class="storeBox">
                    <volist name="vo" id="ro">
                        <div class="list-item">
                            <div class="list-img"><a href="{:U('Good/GoodInfo',array('id'=>$ro[id]))}"><img src="__UPLOAD__thumb/{$ro.thumb}" alt="" width="80" /></a></div>
                            <div class="list-content">

                                <a href="{:U('Good/GoodInfo',array('id'=>$ro[id]))}"><h3 class="list-title">{$ro.name}</h3></a>
                                <p class="list-price"><em>￥{$ro.shop_price}</em>&nbsp;</p>
                                <if condition="($ko[promote_price] gt '0')">
                                    <div class="list-main">微信支付<span>立减<i>{$ko.promote_price}</i>元</span></div>
                                </if>
                                <div class="list-add">
                                    <em class="prev" data="{$ro.id}" style="display: inline-block;">-</em>
                                    <if condition="$ro[cart_number] neq '0'">
                                        <input style="display:inline-block; background: #FFFFFF;" type="text" size="5" value="{$ro.cart_number}" disabled="disabled">
                                    </if>
                                    <em class="next" data="{$ro.id}" style="border:1px solid #FF0000;">+</em>
                                </div>
                            </div>
                        </div>
                    </volist>
				</div>
                </volist>
				<!--第二个循环-->
				<div class="storeBox">
                    <volist name="sellerProduct" id="ko">
                        <div class="list-item">
                            <div class="list-img"><a href="{:U('Good/GoodInfo',array('id'=>$ko[id]))}"><img src="__UPLOAD__thumb/{$ko.thumb}" width="80" alt="" /></a></div>
                            <div class="list-content">
                                <a href="{:U('Good/GoodInfo',array('id'=>$ko[id]))}"><h3 class="list-title">{$ko.name}</h3></a>
                                <p class="list-price"><em>￥{$ko.shop_price}</em>&nbsp;</p>

                                <!--<div class="list-main">微信支付<span>立减<i>{$ko.promote_price}</i>元</span></div>-->

                                <div class="list-add">
                                    <em class="prev" data="{$ko.id}" style="display:inline-block">-</em>
                                        <input style="display:inline-block;" type="text" size="5" value="{$ko.cart_number}" disabled="disabled">
                                    <em class="next" data="{$ko.id}" style="border:1px solid #FF0000;">+</em>
                                </div>
                            </div>
                        </div>
                    </volist>
				</div>
			</div>
		
			<div class="addUp">
				<div class="s_shopping"><i class="s_icon s_up"></i><em id="cartNum">{$cartNum}</em></div>
				<div class="total">总计:<p>￥<em id="cartPrice">{$cartPrice}</em></p></div>
				<div class="settlement"><a style="color:#FFFFFF" href="{:U('Order/cart')}">去结算</a></div>
			</div>
		</div>
	</body>
</html>

<script type="text/javascript">
    $(document).ready(
        function(){
            $('.num').each(
                function(){
                    if($(this).text()<="0")
                    {
                        $(this).hide();
                    }
                }
            );

            var storeBox = $('.storeBox');
            var storeNav = $('.storeNav');

            for(var i=0;i<=storeBox.length;i++)
            {
                var input=storeBox.eq(i).find('input');
                var yanG="";
                for(var j=0;j<=input.length;j++)
                {
                    var yanG1=parseInt(input.eq(j).val());

                    if(yanG1!="undefined")
                    {
                        if(!isNaN(yanG1))
                        {
                            yanG=parseInt(yanG+yanG1);
                        }
                    }
                }

                storeNav.find(".num").eq(i).html(yanG);
                if(yanG<="0")
                {
                    storeNav.find(".num").eq(i).hide();
                }else{
                    storeNav.find(".num").eq(i).show();
                }
            }



            numHide();
        }
    );

    function numHide()
    {

        $('.prev').each(
                function(){

                    var aa = $(this).next("input").val();
                    var bb = parseInt(aa);
                    if(isNaN(bb)||bb==0)
                    {
                        $(this).hide();
                    }
//                    if($(this).text()<=0||isNaN($(this).text()))
//                    {
//                        $(this).hide();
//                    }
                }
        );
    }
//幻灯片
var swiper = new Swiper('.swiper-container', {
    pagination: '.swiper-pagination',
    paginationClickable: true,
    autoplay: 2500,
    loop: true
});

$('.storeMain .storeNav li').click(function(){
	var index = $(this).index();
	show(index);
});

show(0);
function show(index){
	$('.storeMain .storeNav li').removeClass('cur').eq(index).addClass('cur');
	$('.storeBox').hide().eq(index).show();
}

//商品加减统计
var listItem = $('.list-content');
var listAdd  = listItem.find('.list-add');
for(var i=0;i<listItem.length;i++){
	fnMain(listItem.eq(i));
};
		
function fnMain(quantityCur){
	var oPrev = quantityCur.find('.prev');
	var oNext  =   quantityCur.find('.next');
	var formInput =   quantityCur.find('input');
	var num = formInput.val();

//	var num=0;

	function showHide(){
		if(num==0||isNaN(num)){
			oPrev.css({'display':'none'});
			formInput.css({'display':'none'});
		}else{
			oPrev.css({'display':'inline-block'});
			formInput.css({'display':'inline-block'});
		}
	}


	oPrev.click(function(){
		if(num>0){
			num--;
		};
		showHide();
		formInput.val(num);
        var productID=oPrev.attr("data");
        var number=num;
        $.ajax({
            url:"{:U('Index/addCart')}",

            type: 'POST',

            data:{
                productID:productID,
                number:number
            },

            dataType: 'html',

            timeout: 1000,

            error: function(){alert('页面正在加载...');},

            success: function(result){
                var one=result.split("/");
                $("#cartNum").html(one[0]);
                $("#cartPrice").html(one[1]);
            }

        });

        updataCate();
	});
	oNext.click(function(){
		num++;
		showHide();
		formInput.val(num);
        var productID=oNext.attr("data");
        var number=num;
        $.ajax({
            url:"{:U('Index/addCart')}",

            type: 'POST',

            data:{
                productID:productID,
                number:number
            },

            dataType: 'html',

            timeout: 1000,

            error: function(){alert('页面正在加载...');},

            success: function(result){
                var one=result.split("/");
                $("#cartNum").html(one[0]);
                $("#cartPrice").html(one[1])
            }

        });

        updataCate();
	});

    function updataCate()
    {
        var storeBox = $('.storeBox');
        var storeNav = $('.storeNav');


        for(var i=0;i<=storeBox.length;i++)
        {
            var input=storeBox.eq(i).find('input');
            var yanG="";
            for(var j=0;j<=input.length;j++)
            {
                var yanG1=parseInt(input.eq(j).val());

                if(yanG1!="undefined")
                {
                    if(!isNaN(yanG1))
                    {
                        yanG=parseInt(yanG+yanG1);
                    }
                }
            }

            storeNav.find(".num").eq(i).html(yanG);
            if(yanG<="0")
            {
                storeNav.find(".num").eq(i).hide();
            }else{
                storeNav.find(".num").eq(i).show();
            }
        }
    }
};

</script>